import json

import requests

APP_ID = 'wxd2f95c0035fcce80'
APP_secret = 'f1f973b14fee4c7fea48909ecf964be1'


def getOpenID(code):
    url = ' https://api.weixin.qq.com/sns/jscode2session' \
          + '?appid=' + APP_ID \
          + '&secret=' + APP_secret \
          + '&js_code=' + code \
          + '&grant_type=authorization_code'
    response = json.loads(requests.get(url).content)
    if 'openid' not in response:
        return None
    return response['openid']
